import { ArgumentMetadata, BadRequestException, Injectable, PipeTransform } from "@nestjs/common";

@Injectable()
export class ParseIntPipe implements PipeTransform<string, number>{
  transform(value: string, metadata: ArgumentMetadata) {
    const val = parseInt(value, 10);
    console.log('转换数据类型管道传入值--', value);
    console.log('转换数据类型管道传入值类型--', typeof(value));
    console.log('转换数据类型管道传出值--', val);
    
    
    if (isNaN(val)) {
      throw new BadRequestException('数据类型错误');
    }
    return val;
  }
}
